<template>
  <div>
    <div :style="opacityStyle" class="header">
      <router-link to="/" class="iconfont">&#xe787;</router-link>
      <span class="duiqi"></span>
      <button>查看详情</button>
    </div>
  </div>
</template>
<script>
export default {
  name: "detailHeader",
  data() {
    return {
      opacityStyle: {
        opacity: 0
      }
    };
  },
  methods: {
    handleScroll() {
      const top = document.documentElement.scrollTop;
      let opacity = 0;
      if (top > 140) {
        opacity = top / 140;
        console.log(opacity);
        opacity = opacity > 1 ? 1 : opacity;
      } else {
        opacity = 0;
      }
      this.opacityStyle = {
        opacity
      };
    }
  },
  activated() {
    window.addEventListener("scroll", this.handleScroll);
  },
  deactivated() {
    window.removeEventListener("scroll", this.handleScroll);
  }
};
</script>

<style lang='stylus' scoped>
@import '~@/assets/stylus/var.stylu';

.header {
  height: 0.86rem;
  background: $bgColor;
  width: 100%;
  text-align: center;
  position: fixed;
  top: 0;
  z-index 1

  .duiqi {
    line-height: 0.86rem;
  }

  button {
    background: #ccc;
    color: white;
    border-radius: 0.1rem;
    font-size: 0.3rem;
    padding: 0.08rem;
    vertical-align: middle;
  }

  .iconfont {
    padding  0 .3rem 0 .3rem
    float: left;
    line-height .86rem
    background #cccccc
    color white
  }
}
</style>